//
//  UIImage+Extension.m
//  Weibo - OC
//
//  Created by user on 16/4/27.
//  Copyright © 2016年 user. All rights reserved.
//

#import "UIImage+Extension.h"

@implementation UIImage (Extension)

- (UIImage *)scaleInWidth:(int)width{
    
    if (self.size.width < width) {
        
        return self;
    }
    
    CGFloat height = width/self.size.width * self.size.height;
    
    CGRect rect = CGRectMake(0, 0, width, height);
    
    UIGraphicsBeginImageContext(rect.size);
    
    [self drawInRect:rect];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}

@end
